<template>
  <el-table
    :data="lineExitData"
    border
    height="700px"
    v-loading="loadingDialogTable"
    :row-class-name="tableRowClassName"
  >
    <el-table-column label="ID" align="center" key="id" prop="id" width="100">
    </el-table-column>
    <el-table-column
      label="类型"
      align="center"
      key="type"
      prop="type"
      show-overflow-tooltip
    />
    <el-table-column
      label="格号"
      align="center"
      key="grid"
      prop="grid"
      width="60"
      show-overflow-tooltip
    />
    <el-table-column
      label="笼号"
      align="center"
      key="group"
      width="60"
      show-overflow-tooltip
    >
      <template slot-scope="scope">
        {{ scope.row.grid | longNumber }}
      </template>
    </el-table-column>
    <el-table-column
      label="宽度"
      align="center"
      key="width"
      prop="width"
      width="60"
      show-overflow-tooltip
    />
    <el-table-column
      label="高度"
      align="center"
      key="height"
      prop="height"
      width="60"
      show-overflow-tooltip
    >
    </el-table-column>
    <el-table-column
      label="客户名称"
      align="center"
      key="clientName"
      prop="clientName"
      show-overflow-tooltip
    >
    </el-table-column>
    <el-table-column
      label="配片号"
      align="center"
      key="orderNumber"
      show-overflow-tooltip
      width="70"
    >
      <template slot-scope="scope">
        {{ scope.row.optGlass.orderNumber }}
      </template>
    </el-table-column>
    <el-table-column
      label="玻璃位置"
      align="center"
      key="place"
      show-overflow-tooltip
    >
      <template slot-scope="scope">
        <dict-tag
          :options="dict.type.quartz_common_location"
          :value="scope.row.place"
        />
      </template>
    </el-table-column>
    <el-table-column
      label="级别"
      align="center"
      key="urgent"
      show-overflow-tooltip
    >
      <template slot-scope="scope">
       {{ scope.row.optGlass.urgent }}
      </template>
    </el-table-column>
    <el-table-column
      label="状态"
      align="center"
      key="state"
      fit
      show-overflow-tooltip
    >
      <template slot-scope="scope">
        <el-tag v-show="isLocation == 1" :type="scope.row | stateColor">
          {{ scope.row | stateName }}
        </el-tag>
        <el-tag v-show="isLocation == 2" :type="scope.row | stateColor2">
          {{ scope.row | stateName2 }}
        </el-tag>
        <el-tag v-show="isLocation == 3" :type="scope.row | stateColor3">
          {{ scope.row | stateName3 }}
        </el-tag>
      </template>
    </el-table-column>
    <el-table-column
      label="预计产线"
      align="center"
      key="spareFieldStr82"
      show-overflow-tooltip
    >
      <template slot-scope="scope">
        {{
          scope.row.optGlass.spareFieldStr8 
        }}
      </template>
    </el-table-column>
    <el-table-column
      label="位置"
      align="center"
      key="spareFieldStr3"
      show-overflow-tooltip
    >
      <template slot-scope="scope">
        {{ scope.row.optGlass.spareFieldStr3 }}
      </template>
    </el-table-column>
    <el-table-column
      label="生产要求"
      align="center"
      key="spareFieldStr4"
      fit
      show-overflow-tooltip
    >
      <template slot-scope="scope">
        {{ scope.row.optGlass.spareFieldStr4 }}
      </template>
    </el-table-column>
    <el-table-column label="操作" align="center" fixed="right">
      <template slot-scope="scope">
        <el-button
          v-if="
            scope.row.status == 0 &&
            scope.row.state == 0 &&
            scope.row.lineExist != 0
          "
          type="text"
          @click="openLosses([scope.row])"
          >报损</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  dicts: [
    "quartz_glass_state",
    "quartz_common_location_search",
    "quartz_common_location",
  ],
  props: {
    lineExitData: {
      type: Array,
      default: () => {
        return [];
      },
    },
    loadingDialogTable: {
      type: Boolean,
      default: false,
    },
    isLocation: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {};
  },
  methods: {
    openLosses(e) {
      this.$openLosses.showDialog(e, this.isLocation);
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.optGlass.downState == "下架") {
        return "downState";
      } else if (
        row != null &&
        row.id &&
        row.place == "ZKBehindCage" &&
        row.state == "0"
      ) {
        return "success-row";
      } else {
        return "warning-row";
      }
    },
  },
  filters: {
    status(arg) {
      let arr = ["等待", "出片", "强制出片", "配片"];
      return arr[arg];
    },
    colorStatus(arg) {
      let arr = ["info", "primary", "warning", "success"];
      return arr[arg];
    },
    longNumber(arg) {
      let a = Math.ceil(arg / 50);
      return a > 6 ? Math.ceil((300 - arg) / 23) + a : a;
    },
    TagColor(arg) {
      return arg.isProd && arg.num == arg.maxNum
        ? arg.isReach == true
          ? "success"
          : "warning"
        : "danger";
    },
    TextName(arg) {
      return arg.isProd && arg.num == arg.maxNum
        ? arg.isReach == true
          ? "✔已到位"
          : "✔已配齐"
        : "×未配齐";
    },
    stateColor(arg) {
      return arg.optGlass.downState == "下架"
        ? "success"
        : arg.id &&
          arg.place == "ZKBehindCage" &&
          arg.state == "0" &&
          arg.status == "0" &&
          arg.lineExist == "1"
        ? "success"
        : "warning";
    },
    stateName(arg) {
      return arg.optGlass.downState == "下架"
        ? "离线生产"
        : arg.id && arg.place == "ZKBehindCage" && arg.state == "0"
        ? "已到B笼"
        : arg.status == "1" 
        ? "已报损"
        : arg.state == "1" || arg.state == 2
        ? "玻璃异常"
        : arg.lineExist == "0"
        ? "正在生产"
        : !arg.id
        ? "未上线"
        : "未到B笼";
    },
    stateColor2(arg) {
      let places = [
        "ZKReceivingStation1",
        "ZKReceivingStation2",
        "ZKReceivingStation3",
        "ZKReceivingStation4",
      ];
      return arg.optGlass.downState == "下架"
        ? "success"
        : arg.id && places.includes(arg.place) && arg.lineExist == "0"
        ? "success"
        : arg.state != "0" || arg.status != "0" || arg.lineExist != "1"
        ? "danger"
        : "warning";
    },
    stateColor3(arg) {
      return arg.optGlass.downState == "下架"
        ? "success"
        : arg.id &&
          arg.place == 1144 &&
          arg.state == "0" &&
          arg.status == "0" &&
          arg.lineExist == "1"
        ? "success"
        : "warning";
    },
    stateName2(arg) {
      let places = [
        "ZKReceivingStation1",
        "ZKReceivingStation2",
        "ZKReceivingStation3",
        "ZKReceivingStation4",
      ];
      return arg.optGlass.downState == "下架"
        ? "离线生产"
        : arg.state != "0" && arg.id == null
        ? "未生产"
        : arg.state != "0" || arg.state == 2
        ? "玻璃异常"
        : arg.status != "0" 
        ? "已报损"
        : arg.id && places.includes(arg.place) && arg.lineExist == "0"
        ? "✔已生产"
        : arg.lineExist == "0"
        ? "已下线"
        : "×未取片";
    },
    stateName3(arg) {
      let places = [1144];
      return arg.optGlass.downState == "下架"
        ? "离线生产"
        : arg.state != "0" && arg.id == null
        ? "未生产"
        : arg.state != "0"
        ? "已报损"
        : arg.status != "0" || arg.state == 2
        ? "玻璃异常"
        : arg.id && places.includes(arg.place) && arg.lineExist == "0"
        ? "玻璃在笼"
        : arg.lineExist == "0"
        ? "已下线"
        : "正在生产";
    },
  },
};
</script>

<style></style>
